package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.entity.SysOrganizationEntity;
import com.wsoft.system.query.org.OrgInsertQuery;
import com.wsoft.system.query.org.OrgListQuery;
import com.wsoft.system.query.org.OrgSelectQuery;
import com.wsoft.system.query.org.OrgUpdateQuery;
import com.wsoft.system.service.ISysOrganizationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhonglj
 * @since 2024年09月06日 14:10:29
 */
@RestController
@Tag(name = "组织管理")
@RequestMapping("/sys/org")
public class SysOrganizationController {
    @Resource
    private ISysOrganizationService organizationService;

    @Operation(summary = "新增组织", description = "新增组织")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid OrgInsertQuery query) {
        boolean b = organizationService.insert(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改组织", description = "修改组织")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid OrgUpdateQuery query) {
        boolean b = organizationService.update(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除组织", description = "删除组织")
    @PostMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = organizationService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "获取组织详情", description = "获取组织详情")
    @GetMapping("/get")
    public ResponseResult getOrg(@RequestParam("id") Long id) {
        SysOrganizationEntity entity = organizationService.getOrgById(id);
        return ResponseResult.success(entity);
    }
    @Operation(summary = "获取组织列表", description = "获取组织列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody @Valid OrgListQuery query) {
        return ResponseResult.success(organizationService.getOrgList(query));
    }

    @Operation(summary = "获取树形组织列表", description = "获取树形组织列表")
    @GetMapping("/listAllDeptTree")
    public ResponseResult listAllDeptTree() {
        return ResponseResult.success(organizationService.selectOrgListTree());
    }

    @Operation(summary = "根据条件获取组织树", description = "根据条件获取组织树")
    @PostMapping ("/listOrgTreeByQuery")
    public ResponseResult listOrgTreeByQuery(@RequestBody @Valid OrgSelectQuery query) {
        return ResponseResult.success(organizationService.selectOrgListTreeByQuery(query));
    }


}
